package cn.tedu.toa.management.sys.controller;


import cn.tedu.toa.management.commons.vo.Result;
import cn.tedu.toa.management.sys.entity.SysRoles;
import cn.tedu.toa.management.sys.service.SysRolesService;
import cn.tedu.toa.management.sys.vo.RoleVo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author huaqian
 * @since 2021-09-09
 */
@RestController
@RequestMapping("/sys-roles")
public class SysRolesController {
//获取配置文件中的参数  page-size
    @Value("${myconfig.page-size}")
    private Integer pageSize;

    @Autowired
    private SysRolesService rolesService;

    @RequestMapping("/findRolesList")
    public Result findRolesList(String roleName,
                                @RequestParam(defaultValue = "1") Integer pageNum){
       // System.out.println(pageSize);
        PageInfo<SysRoles> pageInfo=rolesService.findRoleList(roleName,pageNum,pageSize);
        return Result.ok(pageInfo);
    }

    @RequestMapping("/saveRole")
    public Result saveRole(SysRoles roles,Integer[] menuIds){
        rolesService.saveRole(roles,menuIds);
        return Result.ok();
    }

    @GetMapping("/delRole")
    public Result delRole(Integer roleId){
        rolesService.delRole(roleId);
        return Result.ok();
    }

    @GetMapping("/findRoleById")
    public Result findRoleById(Integer roleId){
        RoleVo roleVo=rolesService.selectRoleMenusByRoleId(roleId);
        return Result.ok(roleVo);
    }

    @PostMapping("/modifyRole")
    public Result modifyRole(SysRoles roles,Integer[] menuIds){

        rolesService.updateRole(roles,menuIds);
        return Result.ok();
    }

    @GetMapping("/findAllRoles")
    public Result<List<SysRoles>> findAllRoles(){
        List<SysRoles> list=rolesService.findAllRoles();
        return Result.ok(list);
    }



}
